<?php

namespace App\Models;


use App\Service\Tree;

class GoodsCate extends Base
{

    // 用户管理
    protected $table = 'goods_cate';

    // 缓存字段，用于搜索绑定的字段
    protected $cacheFields = ['id', 'status', 'is_propose' ];


    // 获取某个栏目的下级id（用于获取文章）（不包含自己）
    public function getChildIds($id)
    {
        $where = [];
        $lists = $this->getAllCache([], $where);
        // 执行操作
        $tree = new Tree();
        $ids  = $tree->getAllChildId($lists, $id);

        return $ids;
    }

    // 获取顶级
    public function getTopParent($myid)
    {
        $where = [];
        $lists = $this->getAllCache([], $where);

        // 执行操作
        $tree = new Tree();
        $top  = $tree->getTopParent($myid, $lists);

        return $top;
    }

    // 获取父级：可以用于构建面包屑
    public function getAllParent($myid)
    {
        $where = [];
        $lists = $this->getAllCache([], $where);
        // 执行操作
        $tree = new Tree();
        $top  = $tree->getAllParent($myid, $lists);

        return $top;
    }

    // 获取顶级
    public function getChild($myid, $is_all = false)
    {
        $where = [];
        $lists = $this->getAllCache([], $where);

        // 执行操作
        $tree = new Tree();
        $top  = $tree->getChild($lists, $myid, $is_all);

        return $top;
    }

    // 定义验证操作
    public function rules()
    {

        $add = [
        ];

        $edit = [
        ];

        $info = [
        ];


        $rule = [
            'ip'   => 'required',
            'city' => 'required',
            'prov' => 'required',
        ];


        $msg = [
            'id'          => '编号',
            'rank'        => '排序',
            'title'       => '栏目名称',
            'pid'         => '父级id',
            'status'      => '状态（1-是正常）',
            'uid'         => '绑定的用户',
            'keyword'     => '关键字',
            'description' => '描述',
            'ctime'       => '创建时间',
            'mtime'       => '修改时间',
        ];

        return ['rule' => $rule, 'msg' => $msg, 'add' => $add];
    }
}
